<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@page import="bean.Donate"%>
<%@page import="bean.Funding_information"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

<html>
	<head>
		<title>在线捐赠</title>
		<link rel="shortcut icon" href="images/titleico.ico" />
		<link href="css/myA.css" type="text/css" rel="stylesheet">
		<link href="css/myCss.css" type="text/css" rel="stylesheet">
	</head>
	<body>
		<script type="text/javascript">
	function refresh() {
		document.getElementById("imgValidate").src = "yanzm.jsp?date="
				+ new Date().getTime();

	}
</script>

		<%
			String firstPage = request.getHeader("Referer");
			if(firstPage != null && (firstPage.indexOf("checkCode.jsp")==-1)) {
				session.setAttribute("onlineDonate",null);
				session.setAttribute("firstPage","false");
			} else {
				session.setAttribute("firstPage","true");
			}
			if(firstPage == null) {
				session.setAttribute("firstPage","null");
			}
		%>
		
		<%
			
			
		%>
		<%
			ArrayList<String> projectTitles = (ArrayList<String>)session.getAttribute("projectTitles");
			ArrayList<Donate> donate_list = (ArrayList<Donate>) session
					.getAttribute("donate_list");
			ArrayList<Funding_information> funding_information_list = (ArrayList<Funding_information>) session
					.getAttribute("funding_information_list");
			if(projectTitles == null) {
				response.sendRedirect("allTitleProject");
			} else if (donate_list == null) {
				response.sendRedirect("donate?page=online.jsp");
			} else if (funding_information_list == null) {
				response.sendRedirect("funding_information?page=online.jsp");
			}
		%>
		<jsp:include page="top.jsp"></jsp:include>
		<table cellpadding="0" cellspacing="0" align="center" width="960">
			<tr valign="top">
				<td>
					<jsp:include page="leftshow.jsp"></jsp:include></td>
				<td>
					<table cellspacing="0" cellpadding="0" width="630" align="right">
						<tr>
							<td>
								<hr color="#CC9966">
							</td>
						</tr>
						<tr>
							<td style="padding-left: 15">
								<img src="images/n_zxjz.jpg" height="20" />
							</td>
						</tr>

						<tr>
							<td>
								<hr color="#CC9966">
							</td>
						</tr>

						<tr>
							<td>
								<table cellpadding="0" cellspacing="0" width="620">
									<tr>
										<td>
											<p>
												感谢您对山东工商学院教育事业的支持！首先请确认您的银行卡已经开通网上银行
												业务（具体开通方法可参见各银行网站），然后填写以下信息，点击下一步。本系统将引导 您在网上进行捐赠，带
												<span style="color: red">*</span>号为必填项。
											</p>
											<p>
												如需捐赠收据，请在留言中说明 并确保通讯地址的有效性，我们会在捐赠到帐后给您寄送。
											</p>

										</td>
									</tr>
									<tr>
										<td style="padding-top: 15">
											<hr style="border: 1px dashed #D3D3D3" align="center"
												width="550">
										</td>
									</tr>
									<tr>
										<td>
											<form action="check/checkCode.jsp" method="post" name="onlineForm">
												<table cellpadding="2" cellspacing="0" width="550"
													align="center">
													<tr>
														<td>
															<span style="color: red">*</span>请输入您要捐赠的金额：(人民币 RMB 单位
															元，整数，最低 1 元)
														</td>
													</tr>
													<tr>
														<td>
															<input type="text" name="onlinePrice" size="30" value="${onlineDonate.donate_price}"/>元 (最多精确到分)
														</td>
													</tr>
													<tr>
														<td>
															请输入您要捐赠的项目：
														</td>
													</tr>
													<tr>
														<td>
															<select name="onlineProject">
																<option selected value="无指定项目">
																	无指定项目
																</option>
																<c:forEach items="${projectTitles}" var="projectTitle">
																	<option value="${projectTitle }">
																		${projectTitle }
																	</option>
																</c:forEach>
															</select>
														</td>
													</tr>
													<tr>
														<td>
															<span style="color: red">*</span>请输入您的姓名：
														</td>
													</tr>
													<tr>
														<td>
															<input type="text" name="onlineName" size="30" value="${onlineDonate.donate_name }"/>
														</td>
													</tr>
													<tr>
														<td>
															<span style="color: red">*</span>请输入您的E-mail：
														</td>
													</tr>
													<tr>
														<td>
															<input type="text" name="onlineEmail" size="50" value="${onlineDonate.donate_email }"/>
														</td>
													</tr>
													<tr>
														<td>
															请输入您的联系电话：
														</td>
													</tr>
													<tr>
														<td>
															<input type="text" name="onlineTelephone" size="30" value="${onlineDonate.donate_telephone }"/>
														</td>
													</tr>
													<tr>
														<td>
															请输入您的地址：
														</td>
													</tr>
													<tr>
														<td>
															<input type="text" name="onlineAddress" size="50" value="${onlineDonate.donate_address }"/>
														</td>
													</tr>
													<tr>
														<td>
															请输入您的邮编：
														</td>
													</tr>
													<tr>
														<td>
															<input type="text" name="onlinePostalcode" size="30" value="${onlineDonate.donate_postalcode }"/>
														</td>
													</tr>
													<tr>
														<td style="padding-top: 15">
															<hr style="border: 1px dashed #D3D3D3" align="center"
																width="550">
														</td>
													</tr>
													<tr>
														<td>
															<input type="radio" name="onlineAlumni" value="yes"
																onclick=
	onlineHideYes();;
checked />
															校友
															<input type="radio" name="onlineAlumni" value="no"
																onclick=
	onlineHideNo();;
/>
															非校友
														</td>
													</tr>
													<tr id="onlineTr1">
														<td>
															<span style="color: red">*</span>请输入您的入学时间及院部
														</td>
													</tr>
													<tr id="onlineTr2">
														<td>
															<input type="text" name="onlineClassInformation" size="30" value="${onlineDonate.donate_classInformation }"/>
															(如：10计算机科学与技术学院或10学生处)
														</td>
													</tr>
													<tr>
														<td style="padding-top: 15">
															<hr style="border: 1px dashed #D3D3D3" align="center"
																width="550">
														</td>
													</tr>
													<tr>
														<td>
															<div align="left">
																留 言：
															</div>
														</td>
													</tr>
													<tr>
														<td>
															<textarea name="onlineContent" cols="50" rows="6">${onlineDonate.remark }</textarea>
														</td>

													</tr>

													<tr>
														<td>
															<span style="color: red">*</span>验证码：
															<input type="text" name="checkcode" size=10 />
															<img name=imgValidate id=imgValidate src="yanzm.jsp"
																onclick=
	refresh();
/>
															<span style="color: blue">点击图片换一张？</span>
														</td>
													</tr>
													<tr>
														<td style="padding-left: 150; padding-top: 20">
															<input type="button" value="确认捐款" onclick="onlineSubmitCheck()"/>
														</td>
													</tr>
												</table>
											</form>
										</td>
									</tr>
								</table>
							</td>
						</tr>
					</table>
				</td>
			</tr>
		</table>
		<script type="text/javascript">
		//默认设置是否是校友
	if("${firstPage}" == "true") {
		if("${onlineDonate.donate_alumni}" == "yes") {
			onlineHideYes();
			for(var i=0;i<document.onlineForm.onlineAlumni.length;i++) {
				if("${onlineDonate.donate_alumni}" == document.onlineForm.onlineAlumni[i].value) {
					document.onlineForm.onlineAlumni[i].checked = true;
					break;
				}
				document.onlineForm.onlineAlumni[i].checked = false;
			}
		}else {
			onlineHideNo();
			for(var i=0;i<document.onlineForm.onlineAlumni.length;i++) {
				if("${onlineDonate.donate_alumni}" == document.onlineForm.onlineAlumni[i].value) {
					document.onlineForm.onlineAlumni[i].checked = true;
					break;
				}
				document.onlineForm.onlineAlumni[i].checked = false;
			}
		}
	
		//设置属于哪个基金会项目
		for(var i=0;i<document.onlineForm.onlineProject.length;i++) {
			if(document.onlineForm.onlineProject[i].value == "${onlineDonate.donate_need}") {
				document.onlineForm.onlineProject[i].selected = true;
			}
		}
		document.onlineForm.checkcode.focus();
	}
	
		
	function onlineHideYes() {
		document.getElementById("onlineTr1").style.display = "none";
		document.getElementById("onlineTr1").style.display = "";
		document.getElementById("onlineTr2").style.display = "none";
		document.getElementById("onlineTr2").style.display = "";
	}
	function onlineHideNo() {
		document.getElementById("onlineTr1").style.display = "";
		document.getElementById("onlineTr1").style.display = "none";
		document.getElementById("onlineTr2").style.display = "";
		document.getElementById("onlineTr2").style.display = "none";
	}
	function onlineSubmitCheck() {
		var name = document.onlineForm.onlineName.value;
		var price = document.onlineForm.onlinePrice.value;
		var email = document.onlineForm.onlineEmail.value;
		var telephone = document.onlineForm.onlineTelephone.value;
		var postalcode = document.onlineForm.onlinePostalcode.value;
		var checkcode = document.onlineForm.checkcode.value;
		var alumni = "";
		
		for(var i=0;i<document.onlineForm.onlineAlumni.length;i++) {
			if(document.onlineForm.onlineAlumni[i].checked) {
				alumni = document.onlineForm.onlineAlumni[i].value;
			}
		}

		var regexPrice1 = /^[1-9][0-9]*$/;
		var regexPrice2 = /^[1-9][0-9]*\.[0-9]{2}$/;
		var regexPrice3 = /^[1-9][0-9]*\.$/;
		var regexEmail = /^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$/;
		var regexTelePhone = /^[1][3-8][0-9]{9}$/;
		var regexPostcode = /^[1-9][0-9]{5}$/;

		if(price == "") {
			alert("请输入你要捐赠的金额!");
			document.onlineForm.onlinePrice.focus();
		} else if(!regexPrice1.test(price) && !regexPrice2.test(price) && !regexPrice3.test(price)) {
			alert("捐赠金额必须为数字、最低1元且最多精确到分!")
			document.onlineForm.onlinePrice.focus();
		} else if(name == "") {
			alert("请输入您的姓名!");
			document.onlineForm.onlineName.focus();
		} else if(email == "") {
			alert("请输入您的邮箱!")
			document.onlineForm.onlineEmail.focus();
		} else if(!regexEmail.test(email)) {
			alert("邮箱格式不正确!")
			document.onlineForm.onlineEmail.focus();
		} else if(telephone != "" && !regexTelePhone.test(telephone)) {
			alert("电话号码格式不正确!")
			document.onlineForm.onlineTelephone.focus();
		} else if(postalcode != "" && !regexPostcode.test(postalcode)) {
			alert("邮政编码格式不正确!");
			document.onlineForm.onlineTelephone.focus();
		} else if(alumni == "yes") {
			var classInformation = document.onlineForm.onlineClassInformation.value;
			if(classInformation == "") {
				alert("请输入您的入校时间及院部!")
				document.onlineForm.onlineClassInformation.focus();
			} else if(checkcode == "") {
				alert("验证码不能为空!");
				document.onlineForm.checkcode.focus();
			}else {
				document.onlineForm.submit();
			}
		} else if(checkcode == "") {
			alert("验证码不能为空!");
			document.onlineForm.checkcode.focus();
		}else {
				document.onlineForm.submit();
		}
	}
</script>


		<jsp:include page="bottom.jsp"></jsp:include>

		<%
			if(donate_list != null && projectTitles != null && funding_information_list != null ) {
				session.removeAttribute("donate_list");
				session.removeAttribute("projectTitles");
				session.removeAttribute("funding_information_list");
			}
		%>

	</body>
</html>